package eu.jpereira.trainings.designpatterns.structural.facade;

import eu.jpereira.trainings.designpatterns.structural.facade.model.Book;
import eu.jpereira.trainings.designpatterns.structural.facade.model.Customer;
import eu.jpereira.trainings.designpatterns.structural.facade.model.DispatchReceipt;
import eu.jpereira.trainings.designpatterns.structural.facade.model.Order;
import eu.jpereira.trainings.designpatterns.structural.facade.service.BookDBService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.CustomerDBService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.CustomerNotificationService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.OrderingService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.WharehouseService;

public class DefaultBookstoreFacade implements BookstoreFacade {

	private BookDBService bs;
	private Book book;
	private CustomerDBService cs;
	private Customer customer;
	private OrderingService os;
	private Order order;
	private WharehouseService ws;
	private DispatchReceipt dispatchReceipt;
	private CustomerNotificationService cns;

	public DefaultBookstoreFacade() {
	}

	@Override
	public void placeOrder(String customerId, String isbn) {

		book = bs.findBookByISBN(isbn);
		customer = cs.findCustomerById(customerId);
		order = os.createOrder(customer, book);
		dispatchReceipt = ws.dispatch(order);
		cns.notifyClient(dispatchReceipt);
	}

	public void setBookService(BookDBService bs) {
		this.bs = bs;
	}

	@Override
	public void setCustomService(CustomerDBService cs) {
		this.cs = cs;

	}

	@Override
	public void setOrderingService(OrderingService os) {
		this.os = os;

	}

	@Override
	public void setWarehouseService(WharehouseService ws) {
		this.ws = ws;

	}

	@Override
	public void setCustomerNotificationService(CustomerNotificationService cns) {
		this.cns = cns;

	}

}
